<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="style.css">
</head>
<script>
    window.onload = function () {
        var shang = document.getElementById("shang");
        var xia = document.getElementById("xia");
        var img = document.getElementsByTagName("img")[0];
        var arr = ["img/1.jpg","img/2.jpg","img/3.jpg","img/4.jpg","img/5.jpg"];
        var tishi = document.getElementById("p1");
        var index = 0;
        
        shang.onclick = function () {
            index--
            if(index<0){
                index=arr.length-1;
            };
            img.src = arr[index];
           tishi.innerHTML = "一共"+arr.length+"张图片,当前第"+(index+1)+"张";          
        };

        xia.onclick = function () {
            index++
            if(index>arr.length-1){
                index=0;
            };
            img.src = arr[index]
            tishi.innerHTML = "一共"+arr.length+"张图片,当前第"+(index+1)+"张";          
        };
        tishi.innerHTML = "一共"+arr.length+"张图片,当前第"+(index+1)+"张";
    };
</script>
<body>
    <div id="tu">
        <p id="p1"></p>
        <img src="img/1.jpg" width="350px" height="500px">
        <button id="shang">上一张</button>
        <button id="xia">下一张</button>
    </div>
    
    
</body>
</html>